$(() =>{

    //确认按钮
    $('.resolve-btn').on('click', () =>{

        const data = getData()
        let changeFlag = false
        $.each(data, function(key, value){

            if(value != oldData[key]){
                changeFlag = true
                return false
            } 
        })

        //如果没有修改 就直接跳转到个人主页
        !changeFlag && location.replace('http://localhost:3003/personal')

        //否则 发送请求修改数据
        changeFlag && $.ajax({
            type: 'POST',
            url: 'http://localhost:3003/blogsd',
            data,
            dataType: 'json',
            success(res){
                if(res.code === 1){
                    location.replace('http://localhost:3003/personal')
                }
            }
        })

    })

    $('.reject-btn').on('click', () =>{
        location.replace('http://localhost:3003/personal')
    })

    const oldData = getData()

    function getData(){
        const data = {}
        //获取数据
        data.realName = $('#relName').val()
        data.gender = $('#gender').val()
        data.trade = $('#trade').val()
        data.year = $('#year').val()
        data.month = $('#month').val()
        data.data = $('#data').val()
        data.province = $('#province option:selected').text()
        data.city = $('#city option:selected').text()
        data.intronl = $('#intronl').val()

        if(data.province === '省份'){
            data.province = '*'
            data.city = '*'
        }


        return data
    }

})